package zhtt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created by zhtt on 2016/10/28.
 */
@EnableAutoConfiguration
@RestController
@RequestMapping("/user")
@ComponentScan(basePackages = { "zhtt" })
//@EntityScan
//SpringBootApplication
public class UserController {

    @Autowired
    private UserService service;

    @RequestMapping("/{id}/{name}")
    private User view(@PathVariable("id") String id,@PathVariable("name") String name) {
        User user = new User();
        user.setId(id);
        user.setName(name);
        service.save(user);
        return user;
    }

    /**
     *
     运行后访问：http://localhost:8080/user/id/name
     默认端口为：8080
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(UserController.class);
    }
}
